//
//  ViewController.m
//  Core Image自定义 Filter
//
//  Created by quanhao huang on 2019/12/26.
//  Copyright © 2019 quanhao huang. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *imageView1;
@property (weak, nonatomic) IBOutlet UIImageView *imageView2;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 1. 将UIImage转换成CIImage
    CIImage *ciImage = [[CIImage alloc] initWithImage:self.imageView2.image];

    // 2. 创建滤镜
    MirrorXFilter *filter = [[MirrorXFilter alloc] init];
    // 设置相关参数
    [filter setValue:ciImage forKey:@"inputImage"];

    // 3. 渲染并输出CIImage
    CIImage *outputImage = [filter outputImage];

    // 4. 获取绘制上下文
    CIContext *context = [CIContext contextWithOptions:nil];

    // 5. 创建输出CGImage
    CGImageRef cgImage = [context createCGImage:outputImage fromRect:[outputImage extent]];
    UIImage *image = [UIImage imageWithCGImage:cgImage];
    // 6. 释放CGImage
    CGImageRelease(cgImage);
    
    self.imageView2.image = image;
}


@end
